package com.wang.linkedList;

import com.wang.collection.Student;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;

/**
 * 数据结构:双向链表
 */
public class LinkedListDemo {
    public static void main(String[] args) {
        LinkedList<Student> linkedList = new LinkedList<>();
        Student s1 = new Student("wan1",1);
        Student s2 = new Student("wan2",2);
        Student s3 = new Student("wan3",3);
        //1.添加数据
        linkedList.add(s1);
        linkedList.add(s2);
        linkedList.add(s3);
        System.out.println(linkedList.size());
        System.out.println(linkedList.toString());
        //2.删除
//        linkedList.remove(s1);
//        linkedList.remove(0);
        //3.遍历操作
        //1.foreach
        for (Student student : linkedList) {
            System.out.println(student);
        }
        //fori
        for (int i = 0; i < linkedList.size(); i++) {
            System.out.println(linkedList.get(i));
        }
        //iterator
        Iterator<Student> iterator = linkedList.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        //注意这里还有个增强的迭代器 可以正向也可以反向,还可以添加元素
        ListIterator<Student> studentListIterator = linkedList.listIterator();
        while (studentListIterator.hasNext()){
            System.out.println(studentListIterator.next());
        }
        while (studentListIterator.hasPrevious()){
            System.out.println(studentListIterator.hasPrevious());
        }
        //判断 contains  isEmpty
        //获取 indexOf  get
    }
}

